window.onload = function (){
    showLoginInfo();
    showProduct(1);
}

/**
 * 显示商品信息
 * @param pageNO 页码
 */
function showProduct(pageNO){
    axios.get("/product/findByItem",{
        params:{
            pageNO,
            name:$("name").value,
            startDate:$("startDate").value,
            endDate:$("endDate").value
        }
    }).then(e =>{
        var info = e.data;
        //显示商品数据records
        var str = "";
        for(var i=0;i<info.records.length;i++){
            var obj = info.records[i];
            str += `<div><img src="/produtImage/${obj.imgPath}" width="200" height="200"><br>
                    ${obj.name}<br>单价：${obj.price}<br>已售出：${obj.sum}件<br>
                    <a href="/custom/shop.html?productId=${obj.id}">购买</a></div>`;
        }
        $("productDiv").innerHTML = str;

        var cutStr = "";
        for(var i=1;i<=info.pages;i++){
            cutStr += `<a href="javascript:showProduct(${i})">${i}</a> `;
        }
        $("cutPageDiv").innerHTML = cutStr;
    });

}

/**
 * 显示登陆信息
 */
function showLoginInfo(){
    axios.get("/user/getLoginUser",null).then(e => {
        var info =e.data;
        if(info != null && info != '' ){
            $("infoDiv").innerHTML = "欢迎光临，"+info.name;
        }
        else{
            $("infoDiv").innerHTML = "你好，请先<a href='/login.html'>登陆</a>";
        }
    });
}